﻿/// <reference path="Solution.Admin.jCommon.js" />

if (typeof (Solution) == 'undefined') Solution = {};
if (typeof (Solution.Admin) == 'undefined') Solution.Admin = {};
Solution.Admin.SysMenu = {
    Init: function () {
        this.Create();
    },
    gridID: '#List',
    CreateGrid: function (Url, UrlEdit, EditAdvance ) {
        var thisObj = this;
        var Pager = thisObj.gridID + 'Pager';
        var lastselobj = { lastsel: 0 };
        var lastselObj = lastselobj;
        $(thisObj.gridID).jqGrid({
            url: Url,
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Pid', 'Name', 'Display Name', 'Mudule', 'Link', 'flag'],
            colModel: [
                          { name: 'Id', index: 'Id', width: 40, align: 'left', editable: false, editoptions: { readonly: true} },
                          { name: 'Pid', index: 'Pid', width: 200, align: 'left', editable: true },
                          { name: 'Name', index: 'Name', width: 150, align: 'left', editable: true },
                          { name: 'DisplayName', index: 'DisplayName', width: 280, align: 'left', editable: true },
                          { name: 'MName', index: 'MName', width: 150, align: 'left', editable: true },
                          { name: 'Link', index: 'Link', width: 280, align: 'left', editable: true },
                          { name: 'flag', index: 'flag', width: 50, align: 'left', editable: true, hidden: false, viewable: true, recreateForm: true }
                          ],
            pager: jQuery(Pager),
            rowNum: 20,
            rowList: [10, 20, 50],
            height: 400,
            width: 933,
            sortname: 'Id',
            sortorder: "asc",
            viewrecords: true,
            editurl: UrlEdit,
            multiselect: true,
            shrinkToFit: true,
            rownumbers: true,
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true,
                id: "0"
            },
            onSelectRow: function (id) {            
             ondblClickRow: function (id) {
                jQuery(thisObj.gridID).jqGrid('editRow', id, true, '', function (response, postdata) { if (response.responseText != '"err"') { Solution.Admin.Core.ShowNotif('s', 0); thisObj.ReloadGrid(); } else Solution.Admin.Core.ShowNotif('e', -1); return true; }, ''); //  ('editRow', rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc, errorfunc, afterrestorefunc);
                lastselObj.lastsel = id;
            },
            beforeSelectRow: function (id, e) {
                return Solution.Admin.jCommon.beforeSelectRow(thisObj.gridID, id, e, lastselObj);
            },
            caption: ''
        });
        jQuery(thisObj.gridID).jqGrid('navGrid', Pager,
                { add: true, edit: true, del: true },
                { closeAfterEdit: true, afterSubmit: function (response, postdata) { if (response.responseText != '"err"') { Solution.Admin.Core.ShowNotif('s', 0); thisObj.ReloadGrid(); } else Solution.Admin.Core.ShowNotif('e', -1); return true; } },
                { closeAfterAdd: true, afterSubmit: function (response, postdata) { if (response.responseText != '"err"') { Solution.Admin.Core.ShowNotif('s', 0); thisObj.ReloadGrid(); } else Solution.Admin.Core.ShowNotif('e', -1); return true; } }
        );
    },
    Create: function () {
        Solution.Admin.jCommon.CreateNews(this.gridID);
    },
    ReloadGrid: function () {
        Solution.Admin.jCommon.ReloadGrid(this.gridID);
    },
    ShowBin: function (Url, showBin) {
        Solution.Admin.jCommon.ShowBin(this.gridID, Url, showBin);
    },
    DeleteRows: function (_URL, delForever) {
        Solution.Admin.jCommon.DeleteRows(this.gridID, _URL, delForever);
    }
}
